package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;
import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 增加菜品信息
     * @param dish
     */
    @AutoFill(value = OperationType.INSERT)
    void insertdish(Dish dish);

    /**
     * 分页查询菜品
     * @return
     */
    Page<DishVO> findpage(DishPageQueryDTO dishPageQueryDTO);


    /**
     * 获取菜品id
     * @param id
     * @return
     */
    @Select("select *from dish where id=#{id}")
    Dish getByids(Long id);

    /**
     * 删除菜品口味
     * @param id
     */
    @Delete("delete from dish where id=#{Id}")
    void deleteByids(Long id);


    /**
     * 根据id动态修改菜品信息
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    /*
    *根据id查询分类菜品
     */
    List<Dish> list(Dish dish);

    /**
     * 启用禁用菜品状态
     * @param dish
     */
    void startstop(Dish dish);

    /**
     * 获取菜品与套餐左交集对应id 开启禁用套餐用
     * @param id
     * @return
     */
    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long id);


    Integer getcount(HashMap<Object, Object> map);
}
